<template>
  <div class="app-container node-resource">
    <el-table
      :data="list"
      style="width: 100%">
      <el-table-column align="center" label="节点ID">
        <template slot-scope="scope">
          {{ scope.row.nodeId }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="机器类型">
        <template slot-scope="scope">
          {{ scope.row.machineType }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="cpu总数">
        <template slot-scope="scope">
          {{ scope.row.cpu.total }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="cpu剩余">
        <template slot-scope="scope">
          {{ scope.row.cpu.left }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="gpu总数">
        <template slot-scope="scope">
          {{ scope.row.gpu.total }}
        </template>
      </el-table-column>
      <el-table-column align="center" label="gpu剩余">
        <template slot-scope="scope">
          {{ scope.row.gpu.left }}
        </template>
      </el-table-column>
      <!-- <el-table-column align="center" label="gpu隔离">
        <template slot-scope="scope">
          {{ scope.row.gpu.unavailable ? scope.row.gpu.unavailable : '-' }}
        </template>
      </el-table-column> -->
      <el-table-column align="center" label="内存总数">
        <template slot-scope="scope">
          {{ ((scope.row.mem.total / 1024).toFixed(2)) }}GB
        </template>
      </el-table-column>
      <el-table-column align="center" label="内存剩余">
        <template slot-scope="scope">
          {{ (scope.row.mem.left / 1024).toFixed(2) }}GB
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
import { getNodeResource } from '@/api/machine'

export default {
  data() {
    return {
      list: null,
      listLoading: true
    }
  },
  created() {
    this._getNodeResource()
  },
  methods: {
    // 查询节点资源列表
    _getNodeResource() {
      this.listLoading = true
      getNodeResource().then(res => {
        if (res.message.code === 0) {
          this.listLoading = false
          this.list = res.data
        } else {
          this.$message({ message: res.message.message, showClose: true, type: 'error' })
        }
      })
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
.node-resource {
  &-header {
    padding: 10px;
    background: #ffffff;
    font-size: 14px;
    color: #303133;
    font-weight: bold;
    .header-title {
      font-size: 14px;
      font-weight: 700;
    }
  }
  label {
    font-weight: normal
  }
  .table-action {
    color: #4285f4;
  }
  .table-link {
    &:hover {
      color: #4285f4;
    }
  }
}
</style>
